/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package do_.com.bpd.business.referrals.tests;

import do_.bpd.hr.bank.referrals.api.VOReferral;
import java.util.logging.Logger;
import java.util.logging.Level;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import do_.bpd.hr.bank.referrals.api.NonExistentReferral;
import org.junit.Ignore;
import com.google.gson.Gson;
import java.util.Date;
import do_.com.bpd.business.referrals.referralservermanager.impl.IdGen;
import do_.com.bpd.business.referrals.referralservermanager.impl.ReferralManager;
import do_.com.bpd.business.referrals.persistence.entities.Referral;
import do_.com.bpd.business.referrals.referralservermanager.impl.JSONFilter;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Developer
 */
public class LocalTest_1 {

    public LocalTest_1() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }
    // TODO add test methods here.
    // The methods must be annotated with annotation @Test. For example:
    //
    private String checkClientIdFormat(String idClient) {
        String result = null;
        if (idClient != null) {
            result = idClient.replace("-", "");
            result = result.replace(".", "");
            result = result.replace("_", "");
            return result;
        }

        return "";
    }
    @Test
    public void fff()
    {
        String result=checkClientIdFormat("3-4__34.3");
        System.out.println(result);
        
    
    }
@Ignore
    @Test
    public void filterReferral() {
        String formatDate = "yyyy-MM-dd HH:mm:ss";
        String result;

        Date dateS = null;
        Date dateU = null;
        dateS = getDateFromString("2011-07-03 17:50:53", formatDate);
        dateU = getDateFromString("2011-07-04 12:00:02", formatDate);
        JSONFilter j = new JSONFilter();

        j.setKeyword("a");
        j.setFilterType("4");
        j.setDateSince("Dec 9, 2007 6:03:00 PM");
        j.setDateUntil("Dec 19, 2017 11:03:00 PM");

        Gson g = new Gson();
        String json = g.toJson(j);

        result = ReferralManager.getDefault("u15377").filterReferral(json);
        System.out.println("JSON xxxx:" + result);
        assertEquals(result.length() > 2, true);
    }

    @Ignore
    @Test
    public void testCreateReferral() throws Exception {

        VOReferral vo = new VOReferral();
        vo.setId("0");
        vo.setReferralDate("Dec 9, 2007 6:03:00 PM");
        vo.setLoggedUser("12121");
        vo.setReferrerId("u344");

//toJson="{'id':0,'referralCreationDate':null,'referralDate':'12-27-2011','referrerId':'u29975','customerNtlId':'323232','loggedUser':'u29975'}";

//        String createReferral = ReferralManager.getDefault("u15377").createReferral(vo);
//        System.out.println("NEW REFERRAL = " + createReferral);

    }

    public static String getDateStringFromDate(Date date, String format) {
        SimpleDateFormat formatoDeFecha = new SimpleDateFormat(format);
        return formatoDeFecha.format(date);
    }

    public static Date getDateFromString(String date, String format) {
        Date fecha = null;
        try {
            SimpleDateFormat formatoDelTexto = new SimpleDateFormat(format);
            fecha = formatoDelTexto.parse(date);
        } catch (ParseException ex) {
            System.out.println("Error");
        }
        return fecha;
    }
}
